package co.yixiang.modules.material.rest;

import co.yixiang.api.ApiResult;
import co.yixiang.modules.shop.service.YxMaterialService;
import co.yixiang.modules.shop.service.dto.YsMaterialDTO;
import co.yixiang.modules.shop.service.dto.YxMaterialDto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@Api(value = "素材管理", tags = "商城:素材管理")
@RestController
public class MaterialController {

    private final YxMaterialService yxMaterialService;

    public MaterialController(YxMaterialService yxMaterialService) {
        this.yxMaterialService = yxMaterialService;
    }

    @GetMapping(value = "/material/list")
    @ApiOperation(value = "查询素材管理", notes = "素材管理列表")
    public ApiResult<List<YsMaterialDTO>> getYxMaterials(@RequestParam(value = "groupId",defaultValue = "") String groupId,
                                                         @RequestParam(value = "type",defaultValue = "") String type,
                                                         @RequestParam(value = "page",defaultValue = "1") int page,
                                                         @RequestParam(value = "limit",defaultValue = "10") int limit){
        return ApiResult.resultPage(yxMaterialService.getList(type, groupId, page, limit), limit);
    }

    // 新增获取素材详情接口
    @GetMapping(value = "/material/{id}")
    @ApiOperation(value = "获取素材详情", notes = "根据ID查询素材详细信息")
    public ApiResult<YsMaterialDTO> getMaterialDetail(@PathVariable String id) {
        log.info("获取素材详情，ID：{}", id);
        return ApiResult.ok(yxMaterialService.getDTOById(id));
    }


}
